package com.wzy.service.impl;



import com.wzy.dao.StudentDao;
import com.wzy.pojo.Student;
import com.wzy.service.ExternalPopulationService;
import com.wzy.service.StudentService;
import com.wzy.utils.Utils;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service("studentService")
public class StudentServiceImpl implements StudentService {
    @Autowired
    private ExternalPopulationService externalPopulationService;
    SqlSession sqlSession = Utils.getSqlSession();
    StudentDao studentDao = sqlSession.getMapper(StudentDao.class);
    @Override
    public List<Student> findAllStudent() {
        return studentDao.findAllStudent();
    }

    @Override
    public Student findStudent(String ID) {
        return null;
    }

    @Override
    public boolean addStudent(Student s) {
        if(externalPopulationService.findExternalPopulation(s.getID_number())!=null) {
        studentDao.addStudent(s);
        return true;
        }else {
            return false;
        }


    }

    @Override
    public void deleteStudent(String ID) {
        studentDao.deleteStudent(ID);

    }

    @Override
    public void updateStudent(Student s) {
        studentDao.updateStudent(s);

    }
}
